<?php
declare (strict_types = 1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;
use app\common\tool\Result;
use app\common\model\Cate;
use think\facade\View;
use think\Response;
//该文件为自动生成，请按需修改
class Course extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Course';
    
    protected $append = ['cateText'];
    public function index(): string
    {
       return Builder::Table()
           ->autoStructure($this->model, $this->pk, 'barDemo,260')
           ->addRightButtons([
            'add_order' => [
                'size' => '100%',
                'title' => '添加章节', 
                'url' => url('courseChapter/index')->build(),
                'event' => '_openDrawer'
            ],
            'edit' => ['size' => '60%'], 
            'delete'
            ])
           ->addTopButtons(['add' => ['size' => '60%'], 'deleteAll'])
           ->addSearch([
               ['title', '标题', 'input,Like'],
               ['cate', '所属分类', 'selectGroup', self::getCate()]
           ])
           ->fetch();
    }
    /**
     * 获取分类
     */
    public static function getCate()
    {
        $cate = Cate::where('pid',0)->order('sort asc')->field('id,pid,title')->with(['child'])->select();
        return $cate;
    }
}
